<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\PositionApply;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class PositionApplyController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new PositionApply(['user:id,avatar,nickname','position:id,name']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user.avatar','用户头像')->image('',80,80);
            $grid->column('user.nickname','用户昵称');
            $grid->column('position.name','职位名称');
            $grid->column('curriculum_vitae')->downloadable();
            $grid->column('name');
            $grid->column('status')
                ->using([1 => '待跟进',2 => '已跟进'])
                ->label([1 => 'danger',2 => 'success']);

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new PositionApply(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('position_id');
            $show->field('curriculum_vitae');
            $show->field('name');
            $show->field('status');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new PositionApply(['user:id,avatar,nickname','position:id,name']), function (Form $form) {
            $form->display('id');
            $form->image('user.avatar','用户头像')
                ->disable();
            $form->display('user.nickname','用户昵称');
            $form->display('position.name','职位名称');
            $form->display('curriculum_vitae');
            $form->display('name');
            $form->radio('status')
                ->options([1 => '待跟进',2 => '已跟进'])
                ->required();
        });
    }
}
